home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / dateimanager / mtool / source / mfind.c next >
C/C++ Source or Header  |  1996-04-07  |  33KB  |  1,086 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /*  MultiFind   -   Dateiensuche                        Version 1.1r000   */
  4. /*                                                                        */
  5. /*  ©1994 Boris Jakubaschk    Entwicklungszeit: 01.03.1994 - 12.04.1994   */
  6. /*                                                                        */
  7. /*  Versionen:                                                            */
  8. /*                                                                        */
  9. /*  V0.0  01.03.  Entwicklungsbeginn                                      */
  10. /*  V1.0  01.04.  Horizontale Rollbalken eingebaut                        */
  11. /*  V1.1  12.04.  Lokalisiert                                             */
  12. /*                                                                        */
  13. /**************************************************************************/
  14.  
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17. #include <exec/lists.h>
  18. #include <exec/nodes.h>
  19. #include <rexx/storage.h>
  20. #include <intuition/intuition.h>
  21. #include <intuition/classes.h>
  22. #include <intuition/classusr.h>
  23. #include <intuition/imageclass.h>
  24. #include <intuition/gadgetclass.h>
  25. #include <libraries/asl.h>
  26. #include <libraries/gadtools.h>
  27. #include <libraries/locale.h>
  28. #include <graphics/displayinfo.h>
  29. #include <graphics/gfxbase.h>
  30. #include <dos/dostags.h>
  31. #include <workbench/workbench.h>
  32. #include <clib/exec_protos.h>
  33. #include <clib/alib_protos.h>
  34. #include <clib/intuition_protos.h>
  35. #include <clib/gadtools_protos.h>
  36. #include <clib/graphics_protos.h>
  37. #include <clib/rexxsyslib_protos.h>
  38. #include <clib/locale_protos.h>
  39. #include <string.h>
  40.  
  41. #define GD_Pattern                             0
  42. #define GD_type                                1
  43. #define GD_pattern                             2
  44. #define GD_hex                                 3
  45. #define GD_case                                4
  46. #define GD_subdir                              5
  47. #define GD_found                               6
  48. #define GD_source                              7
  49. #define GD_new                                 8
  50. #define GD_del                                 9
  51. #define GD_start                               10
  52. #define GD_stop                                11
  53. #define GD_cancel                              12
  54. #define GD_stat                                13
  55. #define GD_clip                                14
  56. #define GD_mtool                               15
  57. #define GD_edit                                16
  58. #define GD_clear                               17
  59. #define GD_found_vs                            18
  60. #define GD_source_vs                           19
  61.  
  62. #define MSG_Title 0 
  63. #define MSG_Title_Str "MultiFind V1.0 (Boris Jakubaschk)"
  64. #define MSG_FName 1 
  65. #define MSG_FName_Str "Filename"
  66. #define MSG_FCont 2
  67. #define MSG_FCont_Str "Contents"
  68. #define MSG_SPat 3
  69. #define MSG_SPat_Str "Pattern    "
  70. #define MSG_NamesOnly 4
  71. #define MSG_NamesOnly_Str "Filenames only"
  72. #define MSG_HEXMode 5
  73. #define MSG_HEXMode_Str "HEX mode"
  74. #define MSG_CaseSen 6
  75. #define MSG_CaseSen_Str "Case sensitive"
  76. #define MSG_SubDir 7
  77. #define MSG_SubDir_Str "Subdirs"
  78. #define MSG_New 8
  79. #define MSG_New_Str "New"
  80. #define MSG_Del 9
  81. #define MSG_Del_Str "Del"
  82. #define MSG_Start 10
  83. #define MSG_Start_Str "Start"
  84. #define MSG_Stop 11
  85. #define MSG_Stop_Str "Stop"
  86. #define MSG_Cancel 12
  87. #define MSG_Cancel_Str "Cancel"
  88. #define MSG_Clip 13
  89. #define MSG_Clip_Str "Clipboard"
  90. #define MSG_MTool 14
  91. #define MSG_MTool_Str "MTool"
  92. #define MSG_Editor 15
  93. #define MSG_Editor_Str "Editor"
  94. #define MSG_Clear 16
  95. #define MSG_Clear_Str "Clear"
  96. #define MSG_STerm 17
  97. #define MSG_STerm_Str "< finished >"
  98. #define MSG_SCanc 18
  99. #define MSG_SCanc_Str "< cancelled >"
  100. #define MSG_GetPath 19
  101. #define MSG_GetPath_Str "Select the search path or -file"
  102. #define MSG_NoSel 20
  103. #define MSG_NoSel_Str "< no entry selected >"
  104. #define MSG_Welcome 21
  105. #define MSG_Welcome_Str "Welcome to MultiFind!"
  106.  
  107. char *LS[]=
  108.     {
  109.     MSG_Title_Str,
  110.     MSG_FName_Str,
  111.     MSG_FCont_Str,
  112.     MSG_SPat_Str,
  113.     MSG_NamesOnly_Str,
  114.     MSG_HEXMode_Str,
  115.     MSG_CaseSen_Str,
  116.     MSG_SubDir_Str,
  117.     MSG_New_Str,
  118.     MSG_Del_Str,
  119.     MSG_Start_Str,
  120.     MSG_Stop_Str,
  121.     MSG_Cancel_Str,
  122.     MSG_Clip_Str,
  123.     MSG_MTool_Str,
  124.     MSG_Editor_Str,
  125.     MSG_Clear_Str,
  126.     MSG_STerm_Str,
  127.     MSG_SCanc_Str,
  128.     MSG_GetPath_Str,
  129.     MSG_NoSel_Str,
  130.     MSG_Welcome_Str
  131.     };
  132.  
  133. struct Screen        *Scr = NULL;
  134. APTR                  VisualInfo = NULL;
  135. struct Window        *MainWnd = NULL;
  136. struct Gadget        *MainGList = NULL;
  137. struct Gadget        *MainGadgets[20];
  138. UWORD                 MainLeft = 0;
  139. UWORD                 MainTop = 0;
  140. UWORD                 MainWidth = 439;
  141. UWORD                 MainHeight = 269;
  142. UBYTE                *MainWdt = NULL;
  143. struct Library       *CxBase= NULL;
  144. struct DiskObject    *DObj=NULL;
  145.  
  146. char                  Pattern = 1;
  147. char                  HexMode = 0;
  148. char                  CaseSen = 0;
  149. char                  SubDirs = 1;
  150. char                  SearchPattern[256];
  151. char                  PatternMaske[256];
  152. LONG                  TypeCmp = 0;
  153. LONG                  LastSel =-1;
  154. struct List           DirList;
  155. struct List           FoundList;
  156. char                  ActDir[130];
  157. int                   ActOffset;
  158. LONG                  DirScPos = 0;
  159. LONG                  FoundScPos = 0;
  160. LONG                  DirScTot = 0;
  161. LONG                  FoundScTot = 0;
  162.  
  163.  
  164. char *ED_Command;
  165. char *ED_Port;
  166. char *ED_RexxCmd;
  167. char *MT_Port;
  168. char *MT_RexxCmd;
  169.  
  170. struct InfoNode
  171.     {
  172.     struct Node in_Node;
  173.     ULONG in_Offset;
  174.     };
  175.  
  176. UBYTE         *type0Labels[] = {
  177.     (UBYTE *)NULL,
  178.     (UBYTE *)NULL,
  179.     NULL };
  180.  
  181. struct TextAttr topaz8 = {
  182.     ( STRPTR )"topaz.font", 8, 0x00, 0x41 };
  183.  
  184. struct        Library *LocaleBase = NULL;
  185. static struct Catalog *Cat;
  186.  
  187. InitLocale(void)
  188.     {
  189.     char   **str=LS;
  190.     ULONG    i;
  191.     if (LocaleBase=OpenLibrary("locale.library",38))
  192.         {
  193.         if (Cat=(struct Catalog *)OpenCatalog(NULL,"mfind.catalog",
  194.                                    OC_Version, 10,
  195.                                    OC_BuiltInLanguage, "english",
  196.                                    TAG_DONE))
  197.             {
  198.             for (i=0; i<=MSG_Welcome; i++, str++)
  199.                 *str=(char *)GetCatalogStr(Cat,i,*str);
  200.             }
  201.         }
  202.     }
  203.  
  204. QuitLocale(void)
  205.     {
  206.     if (LocaleBase)
  207.         {
  208.         if (Cat) CloseCatalog(Cat);
  209.         CloseLibrary(LocaleBase);
  210.         }
  211.     }
  212.  
  213. int SetupScreen( void )
  214. {
  215.     InitLocale();
  216.  
  217.     if ( ! ( Scr = LockPubScreen( NULL )))
  218.         return( 1L );
  219.  
  220.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  221.         return( 2L );
  222.  
  223.     if ( ! ( CxBase = OpenLibrary( "commodities.library", 37L )))
  224.         return( 3L );
  225.  
  226.     return( 0L );
  227. }
  228.  
  229. void CloseDownScreen( void )
  230.     {
  231.     struct Node *NN;
  232.  
  233.     if ( VisualInfo ) {
  234.         FreeVisualInfo( VisualInfo );
  235.         VisualInfo = NULL;
  236.     }
  237.  
  238.     if ( Scr        ) {
  239.         UnlockPubScreen( NULL, Scr );
  240.         Scr = NULL;
  241.     }
  242.  
  243.     if ( CxBase ) CloseLibrary( CxBase );
  244.     if ( DObj ) FreeDiskObject( DObj );
  245.  
  246.     while ( (&DirList)->lh_Head->ln_Succ )
  247.          {
  248.          NN = DirList.lh_Head;
  249.          Remove( NN );
  250.          FreeMem( NN, sizeof(struct Node)+256 );
  251.          };
  252.  
  253.     while ( (&FoundList)->lh_Head->ln_Succ )
  254.          {
  255.          NN = FoundList.lh_Head;
  256.          Remove( NN );
  257.          FreeMem( NN, sizeof(struct Node)+256 );
  258.          };
  259.  
  260.     QuitLocale();
  261.     }
  262.  
  263. void CenterWnd( WORD WndWidth, WORD *WndHeight, WORD *x_pos, WORD *y_pos )
  264.     {
  265.     ULONG             ModeID;
  266.     struct Rectangle  OSRect;
  267.     WORD              ScrWidth = 0, ScrHeight = 0;
  268.  
  269.     if (INVALID_ID != (ModeID = GetVPModeID(&(Scr->ViewPort) ) ) )
  270.         {
  271.         if (QueryOverscan (ModeID, &OSRect, OSCAN_TEXT) )
  272.             {
  273.             ScrWidth = OSRect.MaxX - OSRect.MinX + 1;
  274.             ScrHeight = OSRect.MaxY - OSRect.MinY + 1;
  275.             };
  276.         };
  277.     *WndHeight = (ScrHeight>320) ? 300 : ScrHeight-12-(ScrHeight%8);
  278.     *x_pos = (ScrWidth/2 - WndWidth/2) - Scr->LeftEdge;
  279.     *y_pos = (ScrHeight/2 - *WndHeight/2) - Scr->TopEdge;
  280.     }
  281.  
  282. int OpenMainWindow( void )
  283. {
  284.     struct NewGadget     ng;
  285.     struct Gadget       *g;
  286.     UWORD               offx, offy;
  287.  
  288.     type0Labels[0] = (UBYTE *)LS[MSG_FName];
  289.     type0Labels[1] = (UBYTE *)LS[MSG_FCont];
  290.     MainWdt = (UBYTE *)LS[MSG_Title];
  291.  
  292.     CenterWnd( MainWidth, &MainHeight, &MainLeft, &MainTop );
  293.  
  294.     offx = Scr->WBorLeft;
  295.     offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  296.  
  297.     if ( ! ( g = CreateContext( &MainGList )))
  298.         return( 1L );
  299.  
  300.     ng.ng_LeftEdge        =    offx + 101;
  301.     ng.ng_TopEdge         =    offy + 3;
  302.     ng.ng_Width           =    201;
  303.     ng.ng_Height          =    14;
  304.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_SPat];
  305.     ng.ng_TextAttr        =    &topaz8;
  306.     ng.ng_GadgetID        =    GD_Pattern;
  307.     ng.ng_Flags           =    PLACETEXT_LEFT;
  308.     ng.ng_VisualInfo      =    VisualInfo;
  309.  
  310.     g = CreateGadget( STRING_KIND, g, &ng, GTST_MaxChars, 256, TAG_DONE );
  311.  
  312.     MainGadgets[ 0 ] = g;
  313.  
  314.     ng.ng_LeftEdge        =    offx + 304;
  315.     ng.ng_Width           =    123;
  316.     ng.ng_GadgetText      =    NULL;
  317.     ng.ng_GadgetID        =    GD_type;
  318.     ng.ng_Flags           =    0;
  319.  
  320.     g = CreateGadget( CYCLE_KIND, g, &ng, GTCY_Labels, &type0Labels[0], TAG_DONE );
  321.  
  322.     MainGadgets[ 1 ] = g;
  323.  
  324.     ng.ng_LeftEdge        =    offx + 101;
  325.     ng.ng_TopEdge         =    offy + 19;
  326.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_NamesOnly];
  327.     ng.ng_GadgetID        =    GD_pattern;
  328.     ng.ng_Flags           =    PLACETEXT_RIGHT;
  329.  
  330.     g = CreateGadget( CHECKBOX_KIND, g, &ng, GTCB_Checked, TRUE, TAG_DONE );
  331.  
  332.     MainGadgets[ 2 ] = g;
  333.  
  334.     ng.ng_TopEdge         =    offy + 32;
  335.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_HEXMode];
  336.     ng.ng_GadgetID        =    GD_hex;
  337.  
  338.     g = CreateGadget( CHECKBOX_KIND, g, &ng, TAG_DONE );
  339.  
  340.     MainGadgets[ 3 ] = g;
  341.  
  342.     ng.ng_LeftEdge        =    offx + 276;
  343.     ng.ng_TopEdge         =    offy + 19;
  344.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_CaseSen];
  345.     ng.ng_GadgetID        =    GD_case;
  346.  
  347.     g = CreateGadget( CHECKBOX_KIND, g, &ng, TAG_DONE );
  348.  
  349.     MainGadgets[ 4 ] = g;
  350.  
  351.     ng.ng_TopEdge         =    offy + 32;
  352.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_SubDir];
  353.     ng.ng_GadgetID        =    GD_subdir;
  354.  
  355.     g = CreateGadget( CHECKBOX_KIND, g, &ng, GTCB_Checked, TRUE, TAG_DONE );
  356.  
  357.     MainGadgets[ 5 ] = g;
  358.  
  359.     ng.ng_LeftEdge        =    offx + 6;
  360.     ng.ng_TopEdge         =    offy + 82;
  361.     ng.ng_Width           =    295;
  362.     ng.ng_Height          =    MainHeight-113;
  363.     ng.ng_GadgetText      =    NULL;
  364.     ng.ng_GadgetID        =    GD_found;
  365.     ng.ng_Flags           =    0;
  366.  
  367.     g = CreateGadget( LISTVIEW_KIND, g, &ng, GTLV_Labels, NULL, TAG_DONE );
  368.  
  369.     MainGadgets[ 6 ] = g;
  370.  
  371.     ng.ng_LeftEdge        =    offx + 304;
  372.     ng.ng_Width           =    123;
  373.     ng.ng_GadgetID        =    GD_source;
  374.  
  375.     g = CreateGadget( LISTVIEW_KIND, g, &ng, GTLV_Labels, &DirList, TAG_DONE );
  376.  
  377.     MainGadgets[ 7 ] = g;
  378.  
  379.     ng.ng_TopEdge         =    offy + 64;
  380.     ng.ng_Width           =    60;
  381.     ng.ng_Height          =    14;
  382.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_New];
  383.     ng.ng_GadgetID        =    GD_new;
  384.     ng.ng_Flags           =    PLACETEXT_IN;
  385.  
  386.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  387.  
  388.     MainGadgets[ 8 ] = g;
  389.  
  390.     ng.ng_LeftEdge        =    offx + 367;
  391.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_Del];
  392.     ng.ng_GadgetID        =    GD_del;
  393.  
  394.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  395.  
  396.     MainGadgets[ 9 ] = g;
  397.  
  398.     ng.ng_LeftEdge        =    offx + 6;
  399.     ng.ng_Width           =    95;
  400.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_Start];
  401.     ng.ng_GadgetID        =    GD_start;
  402.  
  403.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  404.  
  405.     MainGadgets[ 10 ] = g;
  406.  
  407.     ng.ng_LeftEdge        =    offx + 106;
  408.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_Stop];
  409.     ng.ng_GadgetID        =    GD_stop;
  410.  
  411.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  412.  
  413.     MainGadgets[ 11 ] = g;
  414.  
  415.     ng.ng_Width           =    123;
  416.     ng.ng_LeftEdge        =    offx + 304;
  417.     ng.ng_TopEdge         =    offy + MainHeight - 22;
  418.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_Cancel];
  419.     ng.ng_GadgetID        =    GD_cancel;
  420.  
  421.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  422.  
  423.     MainGadgets[ 12 ] = g;
  424.  
  425.     ng.ng_LeftEdge        =    offx + 6;
  426.     ng.ng_TopEdge         =    offy + 46;
  427.     ng.ng_Width           =    421;
  428.     ng.ng_GadgetText      =    NULL;
  429.     ng.ng_GadgetID        =    GD_stat;
  430.  
  431.     g = CreateGadget( TEXT_KIND, g, &ng, GTTX_Border, TRUE, TAG_DONE );
  432.  
  433.     MainGadgets[ 13 ] = g;
  434.  
  435.     ng.ng_LeftEdge        =    offx + 106;
  436.     ng.ng_TopEdge         =    offy + MainHeight - 22;
  437.     ng.ng_Width           =    95;
  438.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_Clip];
  439.     ng.ng_GadgetID        =    GD_clip;
  440.  
  441.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  442.  
  443.     MainGadgets[ 14 ] = g;
  444.  
  445.     ng.ng_LeftEdge        =    offx + 6;
  446.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_MTool];
  447.     ng.ng_GadgetID        =    GD_mtool;
  448.  
  449.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  450.  
  451.     MainGadgets[ 15 ] = g;
  452.  
  453.     ng.ng_LeftEdge        =    offx + 206;
  454.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_Editor];
  455.     ng.ng_GadgetID        =    GD_edit;
  456.  
  457.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  458.  
  459.     MainGadgets[ 16 ] = g;
  460.  
  461.     ng.ng_TopEdge         =    offy + 64;
  462.     ng.ng_LeftEdge        =    offx + 206;
  463.     ng.ng_Width           =    95;
  464.     ng.ng_GadgetText      =    (UBYTE *)LS[MSG_Clear];
  465.     ng.ng_GadgetID        =    GD_clear;
  466.  
  467.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  468.  
  469.     MainGadgets[ 17 ] = g;
  470.  
  471.     ng.ng_LeftEdge        =    offx + 6;
  472.     ng.ng_TopEdge         =    offy + MainHeight - 37;
  473.     ng.ng_Width           =    295;
  474.     ng.ng_Height          =    11;
  475.     ng.ng_GadgetText      =    NULL;
  476.     ng.ng_GadgetID        =    GD_found_vs;
  477.  
  478.     g = CreateGadget( SCROLLER_KIND, g, &ng, GTSC_Total, 0, GTSC_Visible, 33, GTSC_Arrows, 0, GA_RelVerify, TRUE, GA_Immediate, TRUE, TAG_DONE );
  479.  
  480.     MainGadgets[ 18 ] = g;
  481.  
  482.     ng.ng_LeftEdge        =    offx + 304;
  483.     ng.ng_Width           =    123;
  484.     ng.ng_GadgetID        =    GD_source_vs;
  485.  
  486.     g = CreateGadget( SCROLLER_KIND, g, &ng, GTSC_Total, 0, GTSC_Visible, 12, GTSC_Arrows, 0, GA_RelVerify, TRUE, GA_Immediate, TRUE, TAG_DONE );
  487.  
  488.     MainGadgets[ 19 ] = g;
  489.  
  490.     if ( ! g )
  491.         return( 2L );
  492.  
  493.     if ( ! ( MainWnd = OpenWindowTags( NULL,
  494.                     WA_Left,          MainLeft,
  495.                     WA_Top,           MainTop,
  496.                     WA_Width,         MainWidth,
  497.                     WA_Height,        MainHeight + offy,
  498.                     WA_IDCMP,         STRINGIDCMP|CYCLEIDCMP|CHECKBOXIDCMP|LISTVIEWIDCMP|BUTTONIDCMP|TEXTIDCMP|SCROLLERIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  499.                     WA_Flags,         WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  500.                     WA_Gadgets,       MainGList,
  501.                     WA_Title,         MainWdt,
  502.                     WA_ScreenTitle,   "MultiTool II",
  503.                     WA_PubScreen,     Scr,
  504.                     TAG_DONE )))
  505.         return( 4L );
  506.  
  507.     GT_RefreshWindow( MainWnd, NULL );
  508.  
  509.     return( 0L );
  510. }
  511.  
  512. void CloseMainWindow( void )
  513. {
  514.     if ( MainWnd        ) {
  515.         CloseWindow( MainWnd );
  516.         MainWnd = NULL;
  517.     }
  518.  
  519.     if ( MainGList      ) {
  520.         FreeGadgets( MainGList );
  521.         MainGList = NULL;
  522.     }
  523. }
  524.  
  525. int FileRequest( char *Header, char *Buffer, char *StartDrawer )
  526.     {
  527.     struct FileRequester *ASLFiR;
  528.  
  529.     if (ASLFiR = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
  530.                   ASLFR_Window, MainWnd, ASLFR_TitleText, Header,
  531.                   ASLFR_InitialDrawer, StartDrawer,
  532.                   ASLFR_RejectIcons, TRUE, TAG_DONE))
  533.         {
  534.         if (AslRequest( ASLFiR, NULL ))
  535.             {
  536.             strcpy( Buffer, ASLFiR->fr_Drawer );
  537.             AddPart( Buffer, ASLFiR->fr_File, 130 );    
  538.             return(1);
  539.             }
  540.         else return(0);
  541.         };
  542.     }
  543.  
  544. CallEditor( char *Filename, ULONG Offset )
  545.     {
  546.     char Buffer[256];
  547.     char Command[256];
  548.     int Counter=10;
  549.  
  550.     sprintf( Command, ED_Command, Filename );
  551.     SystemTags( Command, SYS_Input, NULL, SYS_Output, NULL, TAG_DONE );
  552.  
  553.     while( (FindPort( ED_Port )==0) && Counter)
  554.         {
  555.         Counter--;
  556.         Delay( 40 );
  557.         };
  558.  
  559.     sprintf( Buffer, "rx \"ADDRESS '%s' '%s'\"", ED_Port, ED_RexxCmd );
  560.     sprintf( Command, Buffer, Offset );
  561.     SystemTags( Command, SYS_Input, NULL, SYS_Output, NULL, TAG_DONE );
  562.     }
  563.  
  564. AddLine( char *Text, ULONG Offset )
  565.     {
  566.     struct Node *NN;
  567.  
  568.     if (NN=AllocMem(sizeof(struct InfoNode)+256, MEMF_ANY|MEMF_CLEAR))
  569.         {
  570.         GT_SetGadgetAttrs( MainGadgets[6], MainWnd, 0, GTLV_Labels, ~0, TAG_DONE );
  571.         NN->ln_Name = ((char *)NN)+sizeof(struct InfoNode);
  572.         ((struct InfoNode*)NN)->in_Offset = Offset;
  573.         strcpy( NN->ln_Name, Text );
  574.         AddTail( &FoundList, (struct Node *)NN );
  575.         GT_SetGadgetAttrs( MainGadgets[6], MainWnd, 0, GTLV_Labels, &FoundList, TAG_DONE );
  576.         if (strlen(Text)>FoundScTot)
  577.             {
  578.             FoundScTot = strlen(Text);
  579.             GT_SetGadgetAttrs( MainGadgets[18], MainWnd, 0, GTSC_Total, FoundScTot, TAG_DONE );
  580.             };
  581.         };
  582.     }
  583.  
  584. int CompareBlock( char *Buffer, ULONG Length )
  585.     {
  586.     ULONG i=0;
  587.     ULONG j;
  588.     ULONG slen = strlen(SearchPattern);
  589.     int Offset;
  590.     char SP[256];
  591.  
  592.     strcpy( SP, SearchPattern );
  593.  
  594.     if ((CaseSen==0)&&(HexMode==0))
  595.         {
  596.         for( i=0; i<strlen(SP); i++ ) SP[i]&=0xDF;
  597.         for( i=0; i<Length; i++ ) Buffer[i]&=0xDF;
  598.         };
  599.  
  600.     if (HexMode)
  601.         {
  602.         for( i=0; i<strlen(SP); i++ )
  603.             {
  604.             if (SearchPattern[i*2+0]>64) { SP[i] = ((SearchPattern[i*2]&0xDF)-55)*16; }
  605.                                     else { SP[i] = (SearchPattern[i*2]-48)*16; };
  606.             if (SearchPattern[i*2+1]>64) { SP[i] += (SearchPattern[i*2+1]&0xDF)-55; }
  607.                                     else { SP[i] += SearchPattern[i*2+1]-48; };
  608.             };
  609.         slen /= 2;
  610.         };
  611.  
  612.     if (Length>=slen)
  613.         {
  614.         for (i=0; i<Length-slen; i++)
  615.             {
  616.             j=0;
  617.             while ((Buffer[i+j]==SP[j])&&(j<slen))
  618.                 {
  619.                 j++;
  620.                 };
  621.             if (j==slen)
  622.                 {
  623.                 Offset = i;
  624.                 i = MAXINT-1;
  625.                 };
  626.             };
  627.         };
  628.     return( (i==MAXINT)?Offset:-1 );
  629.     };
  630.  
  631. int CompareFile( char *Path )
  632.     {
  633.     struct FileInfoBlock *FIB;
  634.     BPTR FL, FH;
  635.     ULONG FileLen = 0;
  636.     ULONG BlockLen, BytesRead;
  637.     char *Buffer;
  638.     int i, Offset;
  639.  
  640.     if (FIB = AllocMem( sizeof(struct FileInfoBlock), MEMF_ANY ))
  641.         {
  642.         if (FL = Lock( Path, ACCESS_READ ))
  643.             {
  644.             if (Examine( FL, FIB ))
  645.                 {
  646.                 FileLen = FIB->fib_Size;
  647.                 };
  648.             UnLock( FL );
  649.             };
  650.         FreeMem( FIB, sizeof(struct FileInfoBlock) );
  651.         };
  652.     if (FileLen)
  653.         {
  654.         BlockLen = (FileLen>65536)? 65536 : FileLen;
  655.         if (Buffer = AllocMem( BlockLen+strlen(SearchPattern), MEMF_ANY ))
  656.             {
  657.             if (FH = Open( Path, MODE_OLDFILE ))
  658.                 {
  659.                 for( i=0; i<((FileLen-1)/BlockLen)+1; i++ )
  660.                     {
  661.                     Seek( FH, i*BlockLen, OFFSET_BEGINNING );
  662.                     BytesRead = Read( FH, Buffer, BlockLen+strlen(SearchPattern) );
  663.                     if ((Offset=CompareBlock( Buffer, BytesRead ))!=-1)
  664.                         {
  665.                         i=MAXINT-1;
  666.                         };
  667.                     };
  668.                 Close( FH );
  669.                 };
  670.             FreeMem( Buffer, BlockLen+strlen(SearchPattern) );
  671.             };
  672.         };
  673.     return( (i==MAXINT)? Offset:-1 );
  674.     }
  675.  
  676. ProcessFile( char *Path, char *Name )
  677.     {
  678.     int success;
  679.  
  680.     switch(TypeCmp)
  681.         {
  682.         case 0: if (CaseSen)
  683.                     {
  684.                     success = MatchPattern( PatternMaske, Name );
  685.                     }
  686.                 else
  687.                     {
  688.                     success = MatchPatternNoCase( PatternMaske, Name );
  689.                     };
  690.                 if (success)
  691.                     {
  692.                     AddLine( Path, 0 );
  693.                     };
  694.                 break;
  695.         case 1: if ((success = CompareFile( Path ))!=-1)
  696.                     {
  697.                     AddLine( Path, success );
  698.                     };
  699.                 break;
  700.         }
  701.     }
  702.  
  703. ProcessDir( char *Path )
  704.     {
  705.     int success;
  706.  
  707.     if((TypeCmp==0)&&(Pattern==0))
  708.         {
  709.         if (CaseSen)
  710.             {
  711.             success = MatchPattern( PatternMaske, Path );
  712.             }
  713.         else
  714.             {
  715.             success = MatchPatternNoCase( PatternMaske, Path );
  716.             };
  717.         if (success)
  718.             {
  719.             AddLine( Path, 0 );
  720.             };
  721.         };
  722.     }
  723.  
  724. int ProcessName( char *Name, char Rekur )
  725.     {
  726.     struct FileInfoBlock *FIB;
  727.     BPTR FL;
  728.     char NewName[130];
  729.     struct IntuiMessage  *msg;
  730.     char DoIt = 1;
  731.  
  732.     GT_SetGadgetAttrs(MainGadgets[13], MainWnd, 0, GTTX_Text, Name, TAG_DONE );
  733.  
  734.     while ( msg = (struct IntuiMessage *) GT_GetIMsg( MainWnd->UserPort ) )
  735.         {
  736.         if( (msg->Class==GADGETUP) &&
  737.             (((struct Gadget *)msg->IAddress)->GadgetID==GD_stop) ) DoIt = 0;
  738.         GT_ReplyIMsg(msg);
  739.         };
  740.  
  741.     if (DoIt)
  742.         {
  743.         if (FIB = AllocMem( sizeof(struct FileInfoBlock), MEMF_ANY ))
  744.             {
  745.             if (FL = Lock( Name, ACCESS_READ ))
  746.                 {
  747.                 if (Examine( FL, FIB ))
  748.                     {
  749.                     if (FIB->fib_DirEntryType>0)
  750.                         {
  751.                         ProcessDir( Name );
  752.                         if (SubDirs || Rekur)
  753.                             {
  754.                             while( ExNext( FL, FIB ) && DoIt )
  755.                                 {
  756.                                 strcpy( NewName, Name );
  757.                                 AddPart( NewName, FIB->fib_FileName, 130 );
  758.                                 DoIt = ProcessName( NewName, 0 );
  759.                                 };
  760.                             };
  761.                         }
  762.                     else
  763.                         {
  764.                         ProcessFile( Name, FIB->fib_FileName );
  765.                         }
  766.                     };
  767.                 UnLock( FL );
  768.                 };
  769.             FreeMem( FIB, sizeof(struct FileInfoBlock) );
  770.             };
  771.         };
  772.     return( DoIt );
  773.     }
  774.  
  775. FindIt()
  776.     {
  777.     struct Node *NN;
  778.     int success = 1;
  779.  
  780.     if ((TypeCmp==0)&&(CaseSen==0))
  781.         {
  782.         success = ParsePatternNoCase( SearchPattern, PatternMaske, 256 )+1;
  783.         }
  784.     else if (TypeCmp==0)
  785.         {
  786.         success = ParsePattern( SearchPattern, PatternMaske, 256 )+1;
  787.         };
  788.  
  789.     if (success)
  790.         {
  791.         NN = DirList.lh_Head;
  792.         while ( NN->ln_Succ )
  793.             {
  794.             if (ProcessName( NN->ln_Name, 1 ))
  795.                 {
  796.                 GT_SetGadgetAttrs(MainGadgets[13], MainWnd, 0, GTTX_Text, LS[MSG_STerm], TAG_DONE );
  797.                 }
  798.             else
  799.                 {
  800.                 GT_SetGadgetAttrs(MainGadgets[13], MainWnd, 0, GTTX_Text, LS[MSG_SCanc], TAG_DONE );
  801.                 };
  802.             NN = NN->ln_Succ;
  803.             };
  804.         };
  805.     }
  806.  
  807. GetPathsFile( char *Name )
  808.     {
  809.     BPTR FH;
  810.     char PN[130];
  811.     char *PName = PN;
  812.     struct Node *NN;
  813.  
  814.     if (FH = Open( Name, MODE_OLDFILE ))
  815.         {
  816.         while( FGets( FH, PName, 130 ) )
  817.             {
  818.             if (PName[strlen(PName)-1]==10) PName[strlen(PName)-1]=0;
  819.             if (PName[strlen(PName)-1]==34) PName[strlen(PName)-1]=0;
  820.             if (PName[strlen(PName)-1]=='?') PName[strlen(PName)-1]=0;
  821.             if (PName[strlen(PName)-1]=='#') PName[strlen(PName)-1]=0;
  822.             if (PName[0]==34) PName++;
  823.             if (NN=AllocMem(sizeof(struct Node)+256, MEMF_ANY|MEMF_CLEAR))
  824.                 {
  825.                 GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, ~0, TAG_DONE );
  826.                 NN->ln_Name = ((char *)NN)+sizeof(struct Node);
  827.                 strcpy( NN->ln_Name, PName );
  828.                 NN->ln_Name += DirScPos;
  829.                 AddTail( &DirList, NN );
  830.                 GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, &DirList, TAG_DONE );
  831.                 if (strlen(PName)>DirScTot)
  832.                     {
  833.                     DirScTot = strlen(PName);
  834.                     GT_SetGadgetAttrs( MainGadgets[19], MainWnd, 0, GTSC_Total, DirScTot, TAG_DONE );
  835.                     }
  836.                 };
  837.             };
  838.         Close( FH );
  839.         };
  840.     }
  841.  
  842. int GetNewPath()
  843.     {
  844.     struct Node *NN;
  845.     char Name[256];
  846.  
  847.     if (FileRequest( LS[MSG_GetPath], Name, "SYS:" ))
  848.         {
  849.         if (NN=AllocMem(sizeof(struct Node)+256, MEMF_ANY|MEMF_CLEAR))
  850.             {
  851.             GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, ~0, TAG_DONE );
  852.             NN->ln_Name = ((char *)NN)+sizeof(struct Node);
  853.             strcpy( NN->ln_Name, Name );
  854.             NN->ln_Name += DirScPos;
  855.             AddTail( &DirList, NN );
  856.             GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, &DirList, TAG_DONE );
  857.             if (strlen(Name)>DirScTot)
  858.                 {
  859.                 DirScTot = strlen(Name);
  860.                 GT_SetGadgetAttrs( MainGadgets[19], MainWnd, 0, GTSC_Total, DirScTot, TAG_DONE );
  861.                 }
  862.             return( 1 );
  863.             };
  864.         };
  865.     return( 0 );
  866.     };
  867.  
  868. MainGadget( struct Gadget *GList, USHORT GCode, WORD GMouseY, ULONG GTimeS, GTimeM )
  869.     {
  870.     static ULONG OTimeS, OTimeM;
  871.     struct Node *NN;
  872.     LONG i;
  873.     char Name[256];
  874.     BPTR FH;
  875.  
  876.     switch (GList->GadgetID)
  877.         {
  878.         case GD_type:
  879.             TypeCmp = GCode;
  880.             break;
  881.         case GD_pattern:
  882.             Pattern ^= 1;
  883.             break;
  884.         case GD_hex:
  885.             HexMode ^= 1;
  886.             break;
  887.         case GD_case:
  888.             CaseSen ^= 1;
  889.             break;
  890.         case GD_subdir:
  891.             SubDirs ^= 1;
  892.             break;
  893.         case GD_source:
  894.             NN = DirList.lh_Head;
  895.             for (i=0; i<GCode; i++) NN = NN->ln_Succ;
  896.             strcpy( ActDir, ((char *)NN)+sizeof(struct Node) );
  897.             ActOffset = 0;
  898.             GT_SetGadgetAttrs(MainGadgets[13], MainWnd, 0, GTTX_Text, ActDir, TAG_DONE );
  899.             LastSel = GCode;
  900.             break;
  901.         case GD_found:
  902.             NN = FoundList.lh_Head;
  903.             for (i=0; i<GCode; i++) NN = NN->ln_Succ;
  904.             strcpy( ActDir, ((char *)NN)+sizeof(struct InfoNode) );
  905.             ActOffset = ((struct InfoNode *)NN)->in_Offset;
  906.             GT_SetGadgetAttrs(MainGadgets[13], MainWnd, 0, GTTX_Text, ActDir, TAG_DONE );
  907.             LastSel = -1;
  908.             break;
  909.         case GD_new:
  910.             GetNewPath();
  911.             break;
  912.         case GD_del:
  913.             if (LastSel!=-1)
  914.                 {
  915.                 NN = DirList.lh_Head;
  916.                 for (i=0; i<LastSel; i++) NN = NN->ln_Succ;
  917.                 GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, ~0, TAG_DONE );
  918.                 Remove( NN );
  919.                 FreeMem( NN, sizeof(struct Node) + 256 );
  920.                 GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, &DirList, TAG_DONE );
  921.                 GT_SetGadgetAttrs(MainGadgets[13], MainWnd, 0, GTTX_Text, LS[MSG_NoSel], TAG_DONE );
  922.                 LastSel = -1;
  923.                 NN = DirList.lh_Head;
  924.                 DirScTot=0;
  925.                 while( NN->ln_Succ )
  926.                     {
  927.                     int a=strlen( ((char *)NN)+sizeof(struct Node ));
  928.                     if (a>DirScTot) DirScTot=a;
  929.                     NN = NN->ln_Succ;
  930.                     }
  931.                 GT_SetGadgetAttrs( MainGadgets[19], MainWnd, 0, GTSC_Total, DirScTot, TAG_DONE );
  932.                 };
  933.             break;
  934.         case GD_start:
  935.             struct StringInfo *sti = MainGadgets[GD_Pattern]->SpecialInfo;
  936.             strcpy( SearchPattern, sti->Buffer );
  937.             FindIt();
  938.             break;
  939.         case GD_clear:
  940.             GT_SetGadgetAttrs( MainGadgets[6], MainWnd, 0, GTLV_Labels, ~0, TAG_DONE );
  941.             while ( (&FoundList)->lh_Head->ln_Succ )
  942.                  {
  943.                  NN = FoundList.lh_Head;
  944.                  Remove( NN );
  945.                  FreeMem( NN, sizeof(struct Node)+256 );
  946.                  };
  947.             GT_SetGadgetAttrs( MainGadgets[6], MainWnd, 0, GTLV_Labels, &FoundList, TAG_DONE );
  948.             FoundScTot = 0;
  949.             FoundScPos = 0;
  950.             GT_SetGadgetAttrs( MainGadgets[18], MainWnd, 0, GTSC_Total, FoundScTot, GTSC_Top, FoundScPos, TAG_DONE );
  951.             break;
  952.         case GD_edit:
  953.             CallEditor( ActDir, ActOffset );
  954.             break;
  955.         case GD_clip:
  956.             sprintf(Name, "FORM   %cFTXTCHRS   %c%s", strlen(ActDir)+12+(strlen(ActDir)%2), strlen(ActDir), ActDir);
  957.             Name[4] = 0;
  958.             Name[5] = 0;
  959.             Name[6] = 0;
  960.             Name[16] = 0;
  961.             Name[17] = 0;
  962.             Name[18] = 0;
  963.             if (FH = Open( "Clips:0", MODE_NEWFILE ))
  964.                 {
  965.                 Write( FH, Name, strlen(ActDir)+20+(strlen(ActDir)%2) );
  966.                 Close( FH );
  967.                 };
  968.             break;
  969.         case GD_cancel:
  970.             CloseMainWindow();
  971.             CloseDownScreen();
  972.             exit(0);
  973.             break;
  974.         case GD_found_vs:
  975.             FoundScPos = GCode;
  976.             GT_SetGadgetAttrs( MainGadgets[6], MainWnd, 0, GTLV_Labels, ~0, TAG_DONE );
  977.             NN = FoundList.lh_Head;
  978.             while( NN->ln_Succ )
  979.                 {
  980.                 NN->ln_Name = ((char *)NN)+sizeof(struct InfoNode) + FoundScPos;
  981.                 NN = NN->ln_Succ;
  982.                 };
  983.             GT_SetGadgetAttrs( MainGadgets[6], MainWnd, 0, GTLV_Labels, &FoundList, TAG_DONE );
  984.             break;
  985.         case GD_source_vs:
  986.             DirScPos = GCode;
  987.             GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, ~0, TAG_DONE );
  988.             NN = DirList.lh_Head;
  989.             while( NN->ln_Succ )
  990.                 {
  991.                 NN->ln_Name = ((char *)NN)+sizeof(struct Node)+DirScPos;
  992.                 NN = NN->ln_Succ;
  993.                 };
  994.             GT_SetGadgetAttrs( MainGadgets[7], MainWnd, 0, GTLV_Labels, &DirList, TAG_DONE );
  995.             break;
  996.         }
  997.     }
  998.  
  999. GetToolTypes(int argc, char **ttarray)
  1000.     {
  1001.     char *pfile;
  1002.  
  1003.     ED_Command = ArgString( ttarray, "ED_Cmd", "EDC %s" );
  1004.     ED_Port = ArgString( ttarray, "ED_Port", "rexx_ced" );
  1005.     ED_RexxCmd = ArgString( ttarray, "ED_RxCmd", "Jump to byte %d" );
  1006.     MT_Port = ArgString( ttarray, "MT_Port", "rexx_mtool" );
  1007.     MT_RexxCmd = ArgString( ttarray, "MT_RxCmd", "Display active %s" );
  1008.     if (ArgString( ttarray, "REQUESTPATHS", NULL ))
  1009.         while (GetNewPath());
  1010.     if (pfile = ArgString( ttarray, "PATHSFILE", NULL ))
  1011.         GetPathsFile(pfile);
  1012.     }
  1013.  
  1014. wbmain(struct WBStartup *WBS)
  1015.     {
  1016.     struct WBArg *WA;
  1017.     BPTR DL;
  1018.     char **tt;
  1019.     
  1020.     WA = &WBS->sm_ArgList[WBS->sm_NumArgs-1];
  1021.     DL = CurrentDir( WA->wa_Lock );
  1022.     if (DObj=(struct DiskObject *)GetDiskObject(WA->wa_Name))
  1023.         {
  1024.         CurrentDir( DL );
  1025.         tt = DObj->do_ToolTypes;
  1026.         commonmain(0, tt);
  1027.         };
  1028.     }
  1029.  
  1030. main(int argc, char **argv)
  1031.     {
  1032.     commonmain(argc, argv);
  1033.     }
  1034.  
  1035. commonmain(int argc, char **argv)
  1036.     {
  1037.     ULONG  GClass;
  1038.     USHORT GCode;
  1039.     UWORD  GQual;
  1040.     ULONG  GTimeS;
  1041.     ULONG  GTimeM;
  1042.     struct Gadget *GList = 0l;
  1043.     WORD   GMouseY;
  1044.     struct IntuiMessage  *msg;
  1045.  
  1046.     if (SetupScreen()) exit(20);
  1047.     NewList(&DirList);
  1048.     NewList(&FoundList);
  1049.     if (OpenMainWindow()) exit(20);
  1050.     GT_SetGadgetAttrs(MainGadgets[13], MainWnd, 0, GTTX_Text, LS[MSG_Welcome], TAG_DONE );
  1051.  
  1052.     GetToolTypes(argc, argv);
  1053.  
  1054.     ActivateGadget( MainGadgets[0] , MainWnd, NULL );
  1055.  
  1056.     for(;;)
  1057.         {
  1058.         Wait( 1 << MainWnd->UserPort->mp_SigBit );
  1059.         while ( msg = (struct IntuiMessage *) GT_GetIMsg( MainWnd->UserPort ) )
  1060.             {
  1061.         GClass  = msg->Class;
  1062.         GCode   = msg->Code;
  1063.         GQual   = msg->Qualifier;
  1064.         if (GClass & (GADGETDOWN | GADGETUP | MOUSEMOVE) )
  1065.                 GList   = (struct Gadget *) msg->IAddress;
  1066.         GMouseY = msg->MouseY;
  1067.         GTimeS  = msg->Seconds;
  1068.         GTimeM  = msg->Micros;
  1069.         GT_ReplyIMsg(msg);
  1070.  
  1071.         switch (GClass)
  1072.             {
  1073.             case CLOSEWINDOW : CloseMainWindow();
  1074.                                CloseDownScreen();
  1075.                                exit(0);
  1076.                                break;
  1077.                 case MOUSEMOVE   :
  1078.             case GADGETUP    : MainGadget( GList, GCode, GMouseY, GTimeS, GTimeM );
  1079.                                break;
  1080.             };
  1081.             };
  1082.         };
  1083.     }
  1084.  
  1085.  
  1086.